<?php
defined('PT_ACCESS') or die('No direct access');

class userModel extends BaseControllers{

	public function login($blank = ''){
		$action = $this->req->getvar('action', '', 'POST');
		$uname = $this->req->getvar('uname', '', 'POST', 'USERNAME');
		$pwd = $this->req->getvar('pwd', '', 'POST');
		$remember = $this->req->getvar('remember', 0, 'POST', 'int');

		// Load language file
		$this->language->load('users/admin_login');

		if (!$this->user->is_loaded()){
			//Login stuff:
			if ($action == 'login'){
				if (isset($uname) && isset($pwd)){
					if (!$this->user->login($uname, $pwd, $remember)){
						//Mention that we don't have to use addslashes as the class do the job
						return $this->language->get('login_fail');
					}else{
						//user is now loaded
						header('HTTP/1.1 301 Moved Permanently');
						header('Location: http://' . $_SERVER['HTTP_HOST'] . $blank);
						exit();
					}
				}
			}
		}else{
			header('HTTP/1.1 301 Moved Permanently');
			header('Location: http://' . $_SERVER['HTTP_HOST'] . $blank);
			exit();
		}
	}

	public function logout($redirect = ''){
		$this->user->logout($redirect);
	}
}